using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ScoreSystem
{
    int noteNum;
    int combo;
    int maxCombo;
    int[] accNum;
    float scorePerNote;

    public void InitSystem(int _noteNum)
    {
        noteNum = _noteNum;
        combo = 0;
        maxCombo = 0;
        accNum = new int[4] { 0, 0, 0, 0 };
        scorePerNote = 2000000f / noteNum;
    }

    public void AddCombo()
    {
        combo++;
        maxCombo = Mathf.Max(maxCombo, combo);
    }

    public void BreakCombo()
    {
        combo = 0;
    }

    public void AddAccNum(AccuracyType type)
    {
        accNum[(int)type]++;
    }

    public int GetMaxCombo()
    {
        return maxCombo;
    }

    public int GetAccNum(AccuracyType type)
    {
        return accNum[(int)type];
    }

    public string GetFinalScore()
    {
        if (accNum[(int)AccuracyType.EXACT] == combo)
        {
            return 2000000.ToString();
        }
        else if (accNum[(int)AccuracyType.HIT] == 0 && accNum[(int)AccuracyType.AWKWARD] == 0)
        {
            return "1" + accNum[(int)AccuracyType.EXACT].ToString().PadLeft(5, '0') + "M";
        }
        else
        {
            return Mathf.RoundToInt(accNum[(int)AccuracyType.EXACT] * scorePerNote
                + accNum[(int)AccuracyType.DEVIATION] * 0.8f * scorePerNote
                + accNum[(int)AccuracyType.HIT] * 0.5f * scorePerNote).ToString();
        }
    }
}
